define(function (require, exports, module) {

    var layout = require("andrew/layout/index.js");
    var sideTree = require("andrew/side-tree/index.js");
    var multiPage = require("andrew/multi-page/index.js");

    var _ = require("lib/lodash.js");

    var api = require("service/home.js");

    window.vueApp = new Vue({
        el: '#app',
        data: {
            innerPage: {
                pages: [{
                    menuName: '卡片演示',
                    url: '03_card.html',
                    active: true
                }],
                hasTop: true,
                //hasTitle: 直接取hastop的反向
            },
            isCollapse: true,
            tree: api.getTree(),
            defaultProps: {
                children: 'children',
                label: 'label'
            }
        },
        mounted: function () {
            $(window).bind("load resize", this.myResize);
            setTimeout(this.myResize, 0);
        },
        methods: {
            innerPageAdd: function (node) {

                if (!this.innerPage.hasTop) {
                    this.innerPage.pages = [];
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }

                var hasIn = false;
                _.forEach(this.innerPage.pages, function (page) {
                    if (page.menuName == node.menuName) {
                        page.active = true;
                        hasIn = true;
                    } else {
                        page.active = false;
                    }

                });


                if (!hasIn) {
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }


            },
            innerPageMove: function (node) {
                var hasIn = false;
                this.innerPage.pages = _.remove(this.innerPage.pages, function (page) {
                    return page.menuName != node.menuName;
                });

                if (this.innerPage.pages.length > 0) {
                    this.innerPage.pages[this.innerPage.pages.length - 1].active = true;
                }
            },
            myResize: function () {
                var outerWidth = $(window).width();
                var outerHeight = $(window).height();
                $("#app").css({
                    height: outerHeight + 'px'
                });
            },
            toggleHasTop: function (to) {
                if (to == undefined) {
                    this.innerPage.hasTop = !this.innerPage.hasTop;
                } else {
                    this.innerPage.hasTop = to;
                }
            }
        }

    });

});